package com.ad.pet.app.serach.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ad.pet.R;
import com.ad.pet.common.data.utils.DensityUtil;
import com.ad.pet.models.remote.mall.FilterAttr;
import com.library.flowlayout.SpaceItemDecoration;

import java.util.List;

/**
 * Created by liuyixiang on 2019/9/21.
 */

public class SearchFilterAdapter extends BaseQuickAdapter<FilterAttr, BaseViewHolder> {
    public SearchFilterAdapter(@Nullable List<FilterAttr> data) {
        super(R.layout.item_filer_attr_layout, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final FilterAttr item) {
        TextView tv_attr = helper.getView(R.id.tv_attr);
        RecyclerView recyclerView = helper.getView(R.id.recycler_attr);
        tv_attr.setText(item.getName());

        final SearchFilterAttrAdapter searchFilterAttrAdapter = new SearchFilterAttrAdapter(item.getAttr_value_list());
        recyclerView.addItemDecoration(new SpaceItemDecoration(DensityUtil.dip2px(5)));
        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 3));
        recyclerView.setAdapter(searchFilterAttrAdapter);


        searchFilterAttrAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position2) {
//                FilterAttrValue filterAttr = searchFilterAttrAdapter.getData().get(position2);
                for (int i = 0; i < item.getAttr_value_list().size(); i++) {
                    item.getAttr_value_list().get(i).setIs_selected(position2 == i ? 1 : 0);
                }
                searchFilterAttrAdapter.notifyDataSetChanged();
            }
        });

    }
}
